<template>
  <backContainer>
    <redoAnswerComponent
      :courseId="courseId"
      :redo-topic-list="redoTopicList"
    >
    </redoAnswerComponent>
  </backContainer>
</template>

<script>
import redoAnswerComponent from './components/redoAnswerComponent'

export default {
  name: 'redoTopicList',
  components: {
    redoAnswerComponent
  },
  data() {
    return {
      courseId: '',
      redoTopicList: []
    }
  },
  created() {
    this.courseId = this.$route.query.courseId - 0
    this.initData()
  },
  beforeDestroy() {
    localStorage.removeItem('redoTopicList')
  },
  methods: {
    initData() {
      let redoTopicList = JSON.parse(localStorage.getItem('redoTopicList'))
      redoTopicList.forEach(item => {
        if (item.answerCount == 0 || item.trueCount == 0) {
          item.answerRange = 0
        } else {
          item.answerRange = Math.round((item.trueCount / item.answerCount) * 100).toFixed(2)
        }
        item.userAnswer = ''
        item.multiAnswers = []
        item.isDeleted = false
        item.right = false
        item.ccTopicOptionList.forEach(optionItem => {
          optionItem.isChecked = false
        })
      })
      this.redoTopicList = redoTopicList
    }
  }
}
</script>

<style scoped>

</style>
